<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t("意见反馈") }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('标题')" prop="title">
        <el-input
          v-model="queryParams.title"
          :placeholder="$t('标题')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="queryHandle"
        >{{ $t("搜索") }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{
          $t("重置")
        }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['system:base:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t("新增") }}</el-button>
      </el-col>
    </el-row>

    <el-table
      v-loading="loading"
      :data="feedbackBaseList"
      border
      tooltip-effect="darkTable"
    >
      <!-- <el-table-column
        :label="$t('序号')"
        type="index"
        align="center"
        show-overflow-tooltip
        width="50"
      >
        <template slot-scope="scope">
          {{
            (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1
          }}
        </template>
      </el-table-column> -->
      <el-table-column :label="$t('工单ID')" align="center" prop="id" />
      <el-table-column :label="$t('问题标题')" align="center" prop="title" />
      <el-table-column :label="$t('问题描述')" align="center" prop="remark" />
      <el-table-column
        :label="$t('提交时间')"
        align="center"
        prop="createTime"
      />
      <el-table-column width="100" :label="$t('状态')" align="center">
        <template slot-scope="scope">
          <el-tag :type="settingColor(scope.row.status)">{{
            getStatus(scope.row.status)
          }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        :label="$t('操作')"
        align="center"
        class-name="small-padding fixed-width"
        width="200"
      >
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['system:base:edit']"
            size="small"
            type="text"
            icon="el-icon-monitor"
            @click="workHandle(scope.row)"
          >{{ $t("详情") }}</el-button>
          <el-button
            v-if="scope.row.status != 'C'"
            size="small"
            type="text"
            icon="el-icon-close"
            @click="closeHandle(scope.row)"
          >{{ $t("关闭") }}</el-button>
          <el-button
            size="small"
            type="text"
            icon="el-icon-delete"
            @click="deleteHandle(scope.row)"
          >{{ $t("删除") }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改客户端-意见反馈对话框 -->
    <el-dialog
      :title="$t(title)"
      :visible.sync="formOpen"
      :close-on-click-modal="false"
      :lock-scroll="false"
      width="30%"
      center
      append-to-body
    >
      <feedbackBaseForm ref="feedbackBaseForm" />
    </el-dialog>
    <div class="chatContent">
      <transition name="el-zoom-in-top">
        <Chat v-if="chatOpen" ref="Chat" @child-close="clsoeChat" />
      </transition>
    </div>
  </div>
</template>

<script>
import {
  listFeedbackBase,
  delFeedbackBase,
  closeFeedbackBase
} from '@/api/system/feedback/feedbackBase'
import feedbackBaseForm from './feedbackBaseForm.vue'
import Chat from './index.vue'
export default {
  components: {
    feedbackBaseForm,
    Chat
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      chatOpen: false,
      // 客户端-意见反馈表格数据
      feedbackBaseList: [],
      // 弹出层标题
      title: '意见反馈',
      // 是否显示弹出层
      formOpen: false,
      workStatus: '',
      // 查询参数
      queryParams: {
        title: undefined,
        pageNum: 1,
        pageSize: 10
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询客户端-意见反馈列表 */
    getList() {
      this.loading = true
      listFeedbackBase(this.queryParams).then((response) => {
        this.feedbackBaseList = response.rows
        this.total = response.total
        this.loading = false
      })
    },

    // 表单重置
    reset() {
      this.form = {
        id: undefined,

        title: undefined,

        remark: undefined,

        createBy: undefined,

        createTime: undefined,

        updateBy: undefined,

        updateTime: undefined,

        delFlag: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
      this.formOpen = true
      this.$nextTick(() => {
        this.$refs.feedbackBaseForm.init(null)
      })
    },
    /** 修改按钮操作 */
    detailsHandle(row) {
      this.formOpen = true
      this.$nextTick(() => {
        // 调用form页面的 init 方法初始化数据
        this.$refs.feedbackBaseForm.init(row)
      })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
      this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        type: 'warning'
      })
        .then(function() {
          return delFeedbackBase(row.id)
        })
        .then(() => {
          this.getList()
          this.msgSuccess(this.$t('删除成功'))
        })
        .catch(function() {})
    },
    closeHandle(row) {
      // 关闭工单
      this.$confirm('确认关闭工单吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          closeFeedbackBase(row.id)
           this.getList()
        })
        .then(() => {
          this.msgSuccess(this.$t('关闭成功'))
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消操作'
          })
        })
    },

    getStatus: function(status) {
      if (status === 'N') {
        return '未处理'
      } else if (status === 'Y') {
        return '已回复'
      } else {
        return '已关闭'
      }
    },
    settingColor(status) {
      if (status === 'N') {
        return ''
      } else if (status === 'Y') {
        return 'success'
      } else {
        return 'danger'
      }
    },
    workHandle(row) {
      // 处理工单
      this.chatOpen = true
      this.$nextTick(() => {
        // 调用form页面的 init 方法初始化数据
        this.$refs.Chat.init(row)
      })
    },
    clsoeChat() {
      this.chatOpen = false
      this.getList()
    }
  }
}
</script>
<style lang="scss" scoped>
.chatContent {
  position: fixed;
  z-index: 999;
  top: -40px;
  left: 50%;
  transform: translateX(-50%);
}
</style>

